import { CaxData } from "../lib";

const data = new CaxData();

data.initS3({
  region: "us-east-1", // 区域可更改
  endpoint: "http://127.0.0.1:9000",
  credentials: {
    accessKeyId: "minioadmin",
    secretAccessKey: "minioadmin",
  },
  maxAttempts: 3,
  requestHandler: {
    connectionTimeout: 2000,
  },
});

// * checkIfExist 测试
data.s3?.checkIfExist("alo.svg").then((res) => {
  if (res === true) {
    console.log("✅ checkIfExist");
  } else {
    console.log("❌ checkIfExist");
  }
});

// 创建一个新的 Blob 对象
const stringToBlob = (str: string) => {
  return new Blob([str], { type: "text/plain" });
};

data.s3
  ?.uploadFile("/test/test.txt", stringToBlob("hello world"))
  .then((res) => {
    console.log(res);
  });
